import Vue from 'vue'
import Router from 'vue-router'

const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/** note: submenu only apppear when children.length>=1
*   detail see  https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
**/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
// 用户登录后，不需要授权的菜单配置在这里
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/login/anonymous', component: _import('login/anonymous/index'), hidden: true },
  { path: '/404', component: _import('error-page/404'), hidden: true },
  { path: '/401', component: _import('error-page/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard-index',
      component: _import('dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/system',
    component: Layout,
    children: [{
      path: 'user/setting/index',
      name: 'system-user-setting-index',
      component: _import('system/user/setting/index'),
      meta: { title: '用户设置' }
    }],
    hidden: true
  },
  {
    path: '/user',
    component: Layout,
    children: [{
      path: 'notice/index',
      name: 'user-notice-index',
      component: _import('user/notice/index'),
      meta: { title: '消息通知' }
    }],
    hidden: true
  },
  {
    path: '/help',
    redirect: '/help',
    component: Layout,
    children: [
      {
        path: 'center/index',
        component: _import('help/center/index'),
        meta: { title: '帮助中心' }
      }
    ],
    hidden: true
  },
  { path: '/register', component: _import('register/index'), hidden: true },
  { path: '/forget-password', component: _import('forget-password/index'), hidden: true }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  // {
  //   path: '/system',
  //   name: 'system',
  //   component: Layout,
  //   redirect: '/system/user/list',
  //   meta: { title: '系统管理', icon: 'setting', roles: ['admin'] },
  //   children: [
  //     {
  //       path: 'user/list',
  //       name: 'system-user-list',
  //       component: _import('system/user/list'),
  //       meta: { title: '用户管理' }
  //     },
  //     {
  //       path: 'role/list',
  //       name: 'system-role-list',
  //       component: _import('system/role/list'),
  //       meta: { title: '角色管理' }
  //     },
  //     {
  //       path: 'permission/list',
  //       name: 'system-permission-list',
  //       component: _import('system/permission/list'),
  //       meta: { title: '菜单权限' }
  //     }
  //   ]
  // },
  // { path: '*', redirect: '/404', hidden: true }
]
